
MockPlaceService = function(opts) {
    this.opts = opts;
};

MockPlaceService.prototype = {
    places: function(opts) {
        var handler = opts.handler;
        var location = opts.location;
        var types = opts.types;
        var radius = opts.radius || 300;

        if (types) {
            types = $.map(types, function(type) { return type.name; });
            types = types.hash();
        }

        var locationPoint = new GeoPoint(location.lat, location.lng);

        var matches = $.grep(this.opts.places, function(p) {
            var placeTypes = $.isArray(p.type) ? p.type : [p.type];
            var typeValid = !types || !!$.grep(placeTypes, function(t) { return types[t.name]; }).length;
            if (typeValid) {
                var placePoint = new GeoPoint(p.lat, p.lng);
                var distance = placePoint.distance(locationPoint);
                return distance <= radius;
            } else {
                return false;
            }
        });
        setTimeout(function() {
            handler(matches);
        }, 0);
    }
};

